﻿using System;
using System.IO;
using System.Web;

namespace AliCMS.UserModule.Bll
{
    public class InstanceConfig : XmlObjectBase, IInstanceConfig
    {
        public InstanceConfig(int instanceID, string lang, bool checkRight, string database)
            : base(instanceID, lang, checkRight)
        {
            string dir = Manager.MapPath(Manager.GetDataPath(instanceID, Lang));
            Manager.MakeSureFolderExist(dir);
            string path = dir + "instance.config";
            if (!File.Exists(path))
            {
                XmlDoc.LoadXml("<?xml version=\"1.0\" encoding=\"utf-8\" ?><configuration></configuration>");
                Save();
                return;
            }
            else
            {
                XmlDoc.Load(path);
            }
        }

        public void Save()
        {
            string path = Manager.MapPath(Manager.GetDataPath(InstanceID, Lang));
            Manager.MakeSureFolderExist(path);

            XmlDoc.Save(path + "instance.config");
        }

        public override object ExecuteService(HttpContext context)
        {
            object result = null;

            string operation = context.Request.QueryString["Operation"];
            if (operation == "SetBasicSettings")
            {
            }
            else
            {
                throw new Exception("lang_header_param");
            }

            return result;
        }

        public bool HasRight(object userData, int instanceInnerID, Guid? subInstanceID, string lang, object objectIDOrName, object operationIDOrName, Guid recordID)
        {
            return true;
        }
    }
}
